﻿/******************************************************************************
  * Copyright  2023 - LiuKuan
  * All right reserved. See COPYRIGHT for detailed Information.
  *
  * @file       LinkManager.h
  * @brief
  * @author     <807874484@qq.com>
  * @date       2024/07/29
  * @history
  *****************************************************************************/

#ifndef LINKMANAGER_H
#define LINKMANAGER_H


#include <QObject>
#include <QList>

#include "Singleton.h"
#include "comm/SerialLink.h"
#include "comm/ModbusRtuLink.h"
#include "controllers/SerialDebugger.h"

class LinkManager : public QObject
{
    Q_OBJECT
    SINGLETON(LinkManager)
    Q_PROPERTY(QStringList   serialPorts   READ serialPorts  NOTIFY serialPortsChanged)
public:
    explicit LinkManager(QObject *parent = nullptr);

//    Q_INVOKABLE SerialLink* getCurrentSerialLink();

    Q_INVOKABLE SerialLink* createSerialLink(const QString & port_name,
                                             int baud,int data_bits,
                                             int stop_bits,int parity);

    Q_INVOKABLE ModbusRtuLink* creatModbusRtuLink(const QString & port_name,
                                                  int baud,int data_bits,
                                                  int stop_bits,int parity);

    Q_INVOKABLE QStringList serialPorts ();
    Q_INVOKABLE void  updateSerialPorts();
signals:
    void serialPortsChanged();
private:
    QString cleanPortDisplayname_(const QString &name);
private:
    QStringList serialPortList_;
    //SerialDebugger debugger_;

};

#endif // LINKMANAGER_H
